home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Tools / HexEdit 1.0.7 ƒ / HexEditSource / Source / HexEdit.h < prev    next >
Text File  |  1994-09-25  |  7KB  |  213 lines

  1. /*********************************************************************
  2.  * HexEdit.h
  3.  *
  4.  * Simple Hex Editor
  5.  * Copyright 1993, Jim Bumgardner
  6.  *
  7.  * Revision History is in History.Note
  8.  *********************************************************************/
  9.  
  10. #include "ObjectWindow.h"
  11. #include <PrintTraps.h>
  12. #include <stdarg.h>
  13.  
  14. #if PROFILE            // 6/15 Optional profiling support
  15. #include <Console.h>
  16. #include <Profile.h>
  17. #endif
  18.  
  19. #define CREATOR            'hDmp'
  20. #define DEFFILETYPE        'TEXT'
  21. #define SBarSize        16
  22. #define    GrowIconSize    14
  23. #define    MainWIND        128
  24. #define MaxFileRAM        32000L
  25. #define SlushRAM        1000L
  26. #define AllocIncr        64L
  27. #define HeaderHeight    20
  28. #define FooterHeight    20
  29. #define TopMargin        3
  30. #define BotMargin        1
  31. #define AddrPos            12
  32. #define HexStart        9
  33. #define AsciiStart        59
  34. #define AsciiSpacing    6
  35. #define LineHeight        11
  36. #define DescendHeight    3
  37. #define CharWidth        6
  38. #define HexWidth        (CharWidth*3)
  39. #define LineNbr(a)        ((a) >> 4)
  40. #define ColNbr(a)        ((a) & 0x0F)
  41. #define CharPos(a)        (((a) << 2) + ((a) << 1))    // Multiply by 6
  42. #define HexPos(a)        (((a) << 4) + ((a) << 1))    // Multiply by 18
  43. #define SaveChangesALRT    10000
  44. #define StdErrorALRT    10001
  45. #define NoForkALRT        10002
  46. #define StdMessageALRT    10003
  47. #define SearchDLOG        128
  48. #define GotoDLOG        129
  49. #define GetFileDLOG        1401
  50. #define MenuBaseID        128
  51. #define UndoSTRs        128
  52. #define MaxWindowWidth    484    // Must be multiple of 2
  53. #define MaxWindowHeight    512    // Note - these are NOT reversed!
  54. #define PrefResType        'prf1'
  55. #define    PrefResID        128
  56.  
  57. enum ChunkTypes        {CT_Original, CT_Work, CT_Unwritten };
  58. enum ForkType         {FT_Data, FT_Resource};
  59. enum ForkModes        {FM_Data, FM_Rsrc, FM_Smart};
  60. enum AsciiModes        {AM_Lo, AM_Hi};
  61. enum EditMode         {EM_Hex, EM_Ascii};
  62. enum EditOperation    {EO_Typing=1, EO_Paste, EO_Insert, EO_Cut, EO_Clear, EO_Delete};
  63. enum ErrorSeverity    {ES_Message, ES_Note, ES_Caution, ES_Stop};
  64. enum CursorNumbers    {C_Arrow, C_Watch, C_IBeam};
  65.  
  66. // Menu Resource IDs
  67. enum    {AppleMENU = 128, FileMENU, EditMENU, FindMENU, OptionsMENU};
  68.  
  69. // Menu Item Numbers
  70. enum    {AM_About=1};
  71.  
  72. enum    {FM_New=1,FM_Open,FM_Close,    
  73.          FM_Save=5, FM_SaveAs, FM_Revert,
  74.          FM_PageSetup=9, FM_Print,
  75.          FM_Quit = 12};
  76.  
  77. enum     {EM_Undo = 1, EM_Cut = 3, EM_Copy,
  78.          EM_Paste, EM_Clear, EM_SelectAll=8};
  79.          
  80. enum    {SM_Find = 1, SM_FindForward, SM_FindBackward, SM_GotoAddress=5};
  81.  
  82. enum    {OM_HiAscii = 1, OM_DecimalAddr, OM_Overwrite, OM_Backups};
  83.  
  84.  
  85. typedef struct EditChunk {
  86.     struct EditChunk    **prev,**next;
  87.     Boolean                loaded;            // Flag if chunk is currently loaded
  88.     short                type;            // 0=Orig File, 1=Work File, 2=Unwritten
  89.     Handle                data;            // Handle to Chunk Data
  90.     long                size;            // Size of Chunk
  91.     long                allocSize;        // Size of allocated pointer
  92.     long                addr;            // Start Addr in updated File
  93.     long                filePos;        // Start Addr in actual File
  94.     long                lastCtr;        // Use Counter
  95. } EditChunk;
  96.  
  97. typedef struct {
  98.     ObjectWindowRecord    oWin;            // Window Record
  99.     ControlHandle        vScrollBar;        // Vertical Scroll Bar
  100.     EditChunk            **firstChunk;    // File's First Chunk
  101.     EditChunk            **curChunk;        // File's Current Chunk
  102.     FSSpec                fsSpec,workSpec;// File Specs for Original, Work File
  103.     FSSpec                destSpec;        // File Spec for Save, Save As
  104.     long                fileSize;        // Total File Size
  105.     long                fileType;        // File Type
  106.     long                creator;        // File Creator
  107.     unsigned long        creationDate;    // Creation Date
  108.     long                useCtr;            // Chunk access Counter
  109.                                         // Chunks are unloaded from memory based on usage
  110.     long                totLoaded;        // Amount of bytes in Memory
  111.     long                editOffset;        // Display Offset
  112.     long                startSel;        // First Character of Selection
  113.     long                endSel;            // First Character AFTER Selection
  114.     long                lastTypePos;    // Last Typing Insertion Point
  115.     short                refNum;            // File's Reference Number
  116.     short                workRefNum;        // Work File's Reference Number
  117.     short                workBytesWritten;    // Size of Work File
  118.     short                linesPerPage;    // Lines that fit in the window
  119.     short                editMode;        // 0=Hex, 1=Ascii
  120.     short                fork;            // 0=data 1=resource
  121.     short                lastNybble;        // Last Hex Edit Nibble
  122.     Boolean                loByteFlag;        // Editing Low Byte for Hex Editor
  123.     Boolean                dirtyFlag;        // File has been modified
  124.     BitMap                bitMap;            // Window's BitMap
  125. } EditWindowRecord, *EditWindowPtr;
  126.  
  127. typedef struct {
  128.     short            type;                // Type of operation
  129.     short            reserved;
  130.     long            startSel;            // Start of Selection
  131.     long            endSel;                // End of Selection
  132.     long            fileSize;            // File Size for Undo Op
  133.     EditChunk        **undoScrap;
  134.     EditWindowPtr    window;
  135. } UndoRecord;
  136.  
  137. typedef struct {
  138.     short    asciiMode;
  139.     short    decimalAddr;
  140.     short    backupFlag;
  141.     short    reserved[29];
  142. } Preferences;
  143.  
  144. extern Preferences    gPrefs;
  145. extern UndoRecord    gUndoRec,gRedoRec;
  146. extern EditChunk    **gScrapChunk,**gSearchChunk;
  147. extern Boolean        gQuitFlag,gSys7Flag,gColorQDFlag;
  148. extern MenuHandle    gAppleMenu, gFileMenu, gEditMenu;
  149. extern short        gScrapCount;
  150. extern THPrint        gHPrint;
  151. extern short        gHighChar, gOverwrite;
  152. extern DialogPtr    gSearchWin;
  153. extern short        gSearchDir;
  154. extern Cursor        gWatchCursor,gIBeamCursor;
  155. extern short        gMaxHeight;
  156.  
  157. // High Level Procedures
  158. void AskEditWindow(void);
  159. void OpenEditWindow(FSSpec *fsSpec);
  160. void DisposeEditWindow(WindowPtr theWindow);
  161. Boolean CloseEditWindow(WindowPtr theWindow);
  162. Boolean CloseAllEditWindow(WindowPtr theWindow);
  163. void MyIdle(WindowPtr theWindow, EventRecord *er);
  164. void MyDraw(WindowPtr theWin);
  165. void MyProcessKey(WindowPtr theWin, EventRecord *er);
  166. void MyActivate(WindowPtr theWin, Boolean active);
  167. void UpdateOnscreen(WindowPtr theWindow);
  168. void MyHandleClick(WindowPtr theWin, Point where, EventRecord *er);
  169. void DrawPage(EditWindowPtr dWin);
  170. void InvertSelection(EditWindowPtr dWin);
  171. void CursorOn(WindowPtr theWin);
  172. void CursorOff(WindowPtr theWin);
  173.  
  174. // Chunk Operatations
  175. void LoadFile(EditWindowPtr dWin);
  176. void UnloadFile(EditWindowPtr dWin);
  177. void DisposeChunk(EditWindowPtr dWin, EditChunk **cc);
  178. EditChunk **NewChunk(long size, long addr, long filePos, short type);
  179. EditChunk **AppendChunk(EditChunk **list, EditChunk **chunk);
  180. EditChunk **GetChunkByAddr(EditWindowPtr dWin, long addr);
  181. short GetByte(EditWindowPtr dWin, long addr);
  182. void LoadChunk(EditWindowPtr dWin, EditChunk **cc);
  183. void UnloadLeastUsedChunk(EditWindowPtr dWin);
  184. void UnloadChunk(EditWindowPtr dWin, EditChunk    **cc, Boolean writeFlag);
  185. void RewriteAddressChain(EditChunk **fc);
  186.  
  187. // Display Operations
  188. void ScrollToSelection(EditWindowPtr dWin, long pos, Boolean forceUpdate, Boolean centerFlag);
  189.  
  190. // Edit Operations (high level)
  191. void UndoSelection(EditWindowPtr dWin);
  192. void CopySelection(EditWindowPtr dWin);
  193. void CutSelection(EditWindowPtr dWin);
  194. void PasteSelection(EditWindowPtr dWin);
  195. void ClearSelection(EditWindowPtr dWin);
  196. void CopyOperation(EditWindowPtr dWin, EditChunk ***scrapChunk);
  197.  
  198. // Edit Operations (low level)
  199. void PasteOperation(EditWindowPtr dWin, EditChunk **scrapChunk);
  200. void RememberOperation(EditWindowPtr dWin, short opType, UndoRecord *ur);
  201. void DeleteSelection(EditWindowPtr dWin);
  202.  
  203. // File Operations
  204. void SaveContents(WindowPtr theWin);
  205. void SaveAsContents(WindowPtr theWin);
  206. void RevertContents(WindowPtr theWin);
  207. void InsureNameIsUnique(FSSpec *tSpec);
  208. short MyRandom(short limit);
  209.  
  210. short ErrorAlert(short severity, char *str,...);
  211. short OSErrorAlert(short severity, char *str, short oe);
  212.  
  213.